from django.db import models

# Create your models here.
from Administrative_office_system.utils.BaseModel import BaseModel


class AttendanceInformation(BaseModel):
    request_data = models.TextField(verbose_name='请求数据', default='')

class ThreePartyAttendanceInformation(BaseModel):
    real_name = models.CharField(verbose_name='姓名', max_length=70, null=True, default='')
    department = models.CharField(verbose_name='科室', max_length=150, null=True, default='')
    job_number = models.CharField(verbose_name='工号', max_length=70, null=True, default='')
    duty_date = models.CharField(verbose_name='值班日期', max_length=100, null=True, default='')
    start_time = models.CharField(verbose_name='开始时间', max_length=100, null=True, default='')
    end_time = models.CharField(verbose_name='结束时间', max_length=100, null=True, default='')
    start_time1 = models.CharField(verbose_name='开始时间', max_length=100, null=True, default='')
    end_time1 = models.CharField(verbose_name='结束时间', max_length=100, null=True, default='')
    rank = models.CharField(verbose_name='班次', max_length=20, null=True, default='')

class CheckInInformation(BaseModel):
    userCode = models.CharField(verbose_name='工号', max_length=70, null=True, default='')
    username = models.CharField(verbose_name='姓名', max_length=70, null=True, default='')
    photo = models.CharField(verbose_name='图片', max_length=255, null=True, default='')
    deviceType = models.CharField(verbose_name='设备类型', max_length=70, null=True, default='')   # 1：人证机 2：考勤机
    deviceCode = models.CharField(verbose_name='设备编码', max_length=70, null=True, default='')
    check_time = models.DateTimeField(verbose_name='打卡时间')

class BeforehandReception(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人'),
        ('two', '分管领导'),
        ('three', '财务科'),
        ('refuse', '拒绝'),
        ('end', '结束'),
        ('stop', '终止'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='one')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='beforehand_reception_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='beforehand_reception_already_audit_users', blank=True)
    note = models.CharField(verbose_name="备注", max_length=255, default='')
    guest_unit_name = models.CharField(verbose_name='来宾单位名称', max_length=225, null=True, default='')
    reception_reason = models.CharField(verbose_name='接待事由', max_length=225, null=True, default='')
    reception_time = models.CharField(verbose_name='接待时间', max_length=50, null=True, default='')
    reception_location = models.CharField(verbose_name='接待地点', max_length=225, null=True, default='')
    budget = models.CharField(verbose_name='经费预算', max_length=70, null=True, default='')
    reception_capacity = models.CharField(verbose_name='接待人数', max_length=30, null=True, default='')
    accompany_meal = models.CharField(verbose_name='陪餐人数', max_length=30, null=True, default='')
    meal_expenses = models.CharField(verbose_name='餐费支出', max_length=70, null=True, default='')
    other_expenses = models.CharField(verbose_name='其他支出', max_length=70, null=True, default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    fj_number = models.CharField('附件id', max_length=50, default='')
    relevance = models.CharField('是否被关联', max_length=10, default='0')

    def get_state_str(self):
        if self.state == 'stop':
            return '终止'
        elif self.state == 'refuse':
            return '拒绝'
        elif self.state == 'end':
            return '结束'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class BeforehandReceptionRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人'),
        ('two', '分管领导'),
        ('three', '财务科')
    )
    parent_id = models.ForeignKey('BeforehandReception', verbose_name="公务（外宾）接待事前审批", blank=False, null=False, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')


class ReceptionChecklist(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人'),
        ('two', '分管领导'),
        ('refuse', '拒绝'),
        ('end', '结束'),
        ('stop', '终止'),
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='one')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='ReceptionChecklist_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='ReceptionChecklist_already_audit_users', blank=True)
    note = models.CharField(verbose_name="备注", max_length=255, default='')
    reception_recipients = models.TextField(verbose_name='接待对象信息', null=True, default='')
    official_interaction = models.CharField(verbose_name='公务互动项目', max_length=225, null=True, default='')
    accompanying_personnel = models.ManyToManyField('personal_center.User', verbose_name='陪餐人员', related_name='accompanying_personnel_users', blank=True)
    reception_time = models.TextField(verbose_name='接待时间', null=True, default='')
    reception_location = models.CharField(verbose_name='接待地点', max_length=225, null=True, default='')
    meal_expenses = models.CharField(verbose_name='餐费支出', max_length=70, null=True, default='')
    other_expenses = models.CharField(verbose_name='其他支出', max_length=70, null=True, default='')
    amount_to = models.CharField(verbose_name='合计', max_length=100, null=True, default='')
    amount_big = models.CharField(verbose_name='合计大写', max_length=125, null=True, default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    fj_number = models.CharField('附件id', max_length=50, default='')
    relevance = models.CharField('是否被关联', max_length=10, default='0')

    def get_state_str(self):
        if self.state == 'stop':
            return '终止'
        elif self.state == 'refuse':
            return '拒绝'
        elif self.state == 'end':
            return '结束'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'


class ReceptionChecklistRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人'),
        ('two', '分管领导')
    )
    parent_id = models.ForeignKey('ReceptionChecklist', verbose_name="公务(外宾)接待清单审批", blank=False, null=False, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')


class EmployeesAbroad(BaseModel):
    STATE = (
        ('draft', '草稿'),
        ('one', '科室负责人'),
        ('two', '监察室'),
        ('three', '分管部门'),
        ('four', '分管领导'),
        ('five', '人事科'),
        ('refuse', '拒绝'),
        ('end', '结束'),
        ('stop', '终止'),
    )
    IDENTITY = (
        ('1', '行管'),
        ('2', '医技/临床'),
        ('3', '护理'),
    )
    POSITION = (
        ('1', "院领导"),
        ('2', "科主任"),
        ('3', "副主任"),
        ('4', "护士长"),
        ('5', "其他")
    )
    apply_user = models.ForeignKey('personal_center.User', verbose_name="申请人", blank=True, null=True, on_delete=models.SET_NULL)
    company = models.ForeignKey('administrative.Company', verbose_name="申请科室", blank=True, null=True, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='one')
    current_audit_users = models.ManyToManyField('personal_center.User', verbose_name='当前审核人员', related_name='employees_abroad_users', blank=True)
    audit_users_already = models.ManyToManyField('personal_center.User', verbose_name='已审核人员', related_name='employees_abroad_already_audit_users', blank=True)
    position_identity = models.CharField('行政身份', max_length=10, choices=IDENTITY, default='1')
    position = models.CharField('职务', max_length=10, choices=POSITION, default='5')
    entry_time = models.CharField('入职时间', max_length=150, default='')
    join_party_time = models.CharField('入党时间', max_length=150, default='')
    onwards_country = models.CharField('前往国家/地区', max_length=150, default='')
    mailing_address_ch = models.CharField('国外通讯处(中文)', max_length=255, default='')
    mailing_address_en = models.CharField('国外通讯处(英文)', max_length=255, default='')
    application_reason = models.CharField('申请理由及期限', max_length=255, default='')
    social_relations_ch = models.TextField(verbose_name='国内直系亲属及主要社会关系情况', null=True, default='')
    social_relations_en = models.TextField(verbose_name='国外直系亲属及主要社会关系情况', null=True, default='')
    restrictive_conditions = models.CharField('是否有《职工出国（境）管理办法》中规定的不得批准出国（境）的情况', max_length=255, default='')
    can_revise = models.CharField('是否可以修改', max_length=50, default='1')
    fj_number = models.CharField('附件id', max_length=50, default='')

    def get_state_str(self):
        if self.state == 'stop':
            return '终止'
        elif self.state == 'refuse':
            return '拒绝'
        elif self.state == 'end':
            return '结束'
        elif self.state == 'draft':
            return '草稿'
        else:
            return '审核中'

class EmployeesAbroadRecord(BaseModel):
    STATE = (
        ('draft', '拒绝'),
        ('audit', '同意'),
        ('unaudit', '待审核'),
    )
    NODE = (
        ('one', '科室负责人'),
        ('two', '监察室'),
        ('three', '分管部门'),
        ('four', '分管领导'),
        ('five', '人事科')
    )
    parent_id = models.ForeignKey('EmployeesAbroad', verbose_name="职工出国（境）审批", blank=False, null=False, on_delete=models.CASCADE)
    state = models.CharField('状态', max_length=10, choices=STATE, default='unaudit')
    audit_people = models.ForeignKey('personal_center.User', verbose_name="审批人", blank=False, null=False, on_delete=models.CASCADE)
    audit_note = models.TextField(verbose_name="审批意见", blank=False)
    node = models.CharField('节点', max_length=10, choices=NODE, default='one')